// API响应类型
export interface ApiResponse<T = any> {
  success: boolean;
  data?: T;
  message?: string;
  meta?: {
    total?: number;
    page?: number;
    limit?: number;
    totalPages?: number;
  };
}

// JWT负载类型
export interface JwtPayload {
  id: number;
  email: string;
  username?: string;
  role?: 'admin' | 'user' | 'merchant' | 'customer_service';
  iat?: number;
  exp?: number;
}

// 用户类型
export interface User {
  id: number;
  email: string;
  username?: string;
  nickname?: string;
  avatar?: string;
  role: 'admin' | 'user' | 'merchant';
  created_at: string;
  updated_at: string;
  last_login_at?: string;
}

// 用户认证相关类型
export interface UserLoginInput {
  email: string; // 登录账号：邮箱、用户名或手机号
  password: string;
}

export interface UserRegisterInput {
  email: string;
  password: string;
  username?: string;
  nickname?: string;
}

// 遗留的 UserCreateInput 类型（保持向后兼容）
export interface UserCreateInput {
  email: string;
  password: string;
  username?: string;
  nickname?: string;
}

export interface UserUpdateInput {
  username?: string;
  nickname?: string;
  avatar?: string;
  current_password?: string;
  new_password?: string;
}

// 地址相关类型
export interface Address {
  id: number;
  user_id: number;
  name: string;
  phone: string;
  province: string;
  city: string;
  district: string;
  detail: string;
  postal_code?: string;
  is_default: boolean;
  created_at: string;
  updated_at: string;
}

export interface AddressCreateInput {
  name: string;
  phone: string;
  province: string;
  city: string;
  district: string;
  detail: string;
  postal_code?: string;
  is_default?: boolean;
}

export interface AddressUpdateInput {
  name?: string;
  phone?: string;
  province?: string;
  city?: string;
  district?: string;
  detail?: string;
  postal_code?: string;
  is_default?: boolean;
}

// 商家相关类型
export interface Merchant {
  id: number;
  name: string;
  type: 'verified' | 'premium' | 'basic';
  rating: number;
  review_count: number;
  location?: string;
  established?: string;
  specialties?: string[];
  logo?: string;
  description?: string;
  certification?: any;
  commission: number;
  status: 'active' | 'inactive';
  user_id?: number;
  created_at: string;
  updated_at: string;
}

export interface MerchantCreateInput {
  name: string;
  type?: 'verified' | 'premium' | 'basic';
  location?: string;
  established?: string;
  specialties?: string[];
  logo?: string;
  description?: string;
  certification?: any;
  commission?: number;
}

export interface MerchantUpdateInput {
  name?: string;
  type?: 'verified' | 'premium' | 'basic';
  location?: string;
  established?: string;
  specialties?: string[];
  logo?: string;
  description?: string;
  certification?: any;
  commission?: number;
  status?: 'active' | 'inactive';
}

// 电脑配置相关类型（基于products表）
export interface ComputerConfig {
  id: number;
  name: string;
  slug: string;
  category_id: number;
  brand?: string;
  model?: string;
  sku?: string;
  price: number;
  original_price?: number;
  stock: number;
  sales: number;
  rating: number;
  review_count: number;
  short_description?: string;
  description?: string;
  specifications?: any;
  features?: any;
  images?: any;
  tags?: any;
  status: 'active' | 'inactive' | 'out_of_stock';
  isFeatured: boolean;
  isHot: boolean;
  meta_title?: string;
  meta_description?: string;
  weight?: number;
  dimensions?: any;
  warranty?: string;
  created_at: string;
  updated_at: string;
}

export interface ComputerConfigCreateInput {
  name: string;
  slug?: string;
  category_id: number;
  brand?: string;
  model?: string;
  sku?: string;
  price: number;
  original_price?: number;
  stock?: number;
  short_description?: string;
  description?: string;
  specifications?: any;
  features?: any;
  images?: any;
  tags?: any;
  isFeatured?: boolean;
  isHot?: boolean;
  meta_title?: string;
  meta_description?: string;
  weight?: number;
  dimensions?: any;
  warranty?: string;
}

export interface ComputerConfigUpdateInput {
  name?: string;
  slug?: string;
  category_id?: number;
  brand?: string;
  model?: string;
  sku?: string;
  price?: number;
  original_price?: number;
  stock?: number;
  short_description?: string;
  description?: string;
  specifications?: any;
  features?: any;
  images?: any;
  tags?: any;
  status?: 'active' | 'inactive' | 'out_of_stock';
  isFeatured?: boolean;
  isHot?: boolean;
  meta_title?: string;
  meta_description?: string;
  weight?: number;
  dimensions?: any;
  warranty?: string;
}

// 订单相关类型
export interface Order {
  id: number;
  order_no: string; // 订单号
  user_id: number;
  product_type: 'product' | 'config' | 'custom'; // 产品类型
  product_id?: number;
  config_id?: number;
  merchant_id: number;
  quantity: number;
  unit_price: number; // 单价
  total_price: number;
  shipping_fee?: number; // 运费
  discount_amount?: number; // 折扣金额
  final_price: number; // 最终价格
  status: 'pending' | 'confirmed' | 'shipped' | 'delivered' | 'cancelled';
  payment_method?: string; // 支付方式
  payment_status?: 'pending' | 'paid' | 'failed' | 'refunded'; // 支付状态
  shipping_address: any;
  notes?: string;
  remark?: string;
  paid_at?: string;
  shipped_at?: string;
  delivered_at?: string;
  created_at: string;
  updated_at: string;
  // 关联数据
  user?: User;
  config?: ComputerConfig;
  merchant?: Merchant;
}

export interface OrderCreateInput {
  config_id?: number;
  product_id?: number;
  product_type?: 'product' | 'config' | 'custom'; // 产品类型
  merchant_id?: number; // 可选，默认为1
  quantity?: number;
  unit_price?: number; // 可选，默认从产品信息获取
  shipping_fee?: number; // 运费
  discount_amount?: number; // 折扣金额
  payment_method?: string; // 支付方式
  shipping_address: any;
  notes?: string;
  remark?: string;
}

export interface OrderUpdateInput {
  status?: 'pending' | 'confirmed' | 'shipped' | 'delivered' | 'cancelled';
  notes?: string;
}

// 查询参数类型
export interface PaginationParams {
  page?: number;
  limit?: number;
}

export interface ComputerConfigQueryParams extends PaginationParams {
  category?: 'office' | 'gaming' | 'workstation';
  category_id?: number;
  brand?: string;
  merchant_id?: number;
  min_price?: number;
  max_price?: number;
  search?: string;
  sort?: 'price_asc' | 'price_desc' | 'sales_desc' | 'newest';
}

export interface OrderQueryParams extends PaginationParams {
  status?: 'pending' | 'confirmed' | 'shipped' | 'delivered' | 'cancelled';
  merchant_id?: number;
  start_date?: string;
  end_date?: string;
} 